package com.sf.web.controller;

import com.sf.qo.QueryObject;
import com.sf.service.IOrderService;
import com.sf.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class OrderController {

    @Autowired
    private IOrderService orderService;

    /**
     * /departmnet/list 请求
     * currentPage  当前页
     */
    @RequestMapping("/order/list")
    public String list(QueryObject queryObject, Model model){
        PageResult result = orderService.query(queryObject);
        // 把数据放到model 中
        model.addAttribute("pageResult",result);
        // 跳转界面
        return "order/list";
    }

    @RequestMapping("/order/buy")
    public String buy(Long productId, HttpSession session){
        // 业务逻辑放到业务层去写
        orderService.buy(productId,session);
        return "redirect:/order/list";
    }

}
